<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class StarRatings
 * This class represents a data access object for the database table 'star_ratings'.
 */
class StarRatings {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: starRatingId, type: int, is nullable: false
	 */
	private $starRatingId  = 0;

	/**
	 * associated database field: starRatingCode, type: varchar, is nullable: true, character set: utf8, max length: 10
	 */
	private $starRatingCode;

	/**
	 * associated database field: starRatingDescription, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $starRatingDescription;


	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("Star_Ratings");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['starRatingId'])) $this->starRatingId = $row['starRatingId'];
		if(isset($row['starRatingCode'])) $this->starRatingCode = $row['starRatingCode'];
		if(isset($row['starRatingDescription'])) $this->starRatingDescription = $row['starRatingDescription'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of StarRatings
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'starRatingId: '.(($escapeQuotationMarks===true) ? addslashes($this->starRatingId) : $this->starRatingId).', ';
		$s .= 'starRatingCode: '.(($escapeQuotationMarks===true) ? addslashes($this->starRatingCode) : $this->starRatingCode).', ';
		$s .= 'starRatingDescription: '.(($escapeQuotationMarks===true) ? addslashes($this->starRatingDescription) : $this->starRatingDescription);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of StarRatings
	 */
	public function toJSONString(){
		$fieldValues = array ("starRatingId"=>$this->starRatingId, "starRatingCode"=>$this->starRatingCode, "starRatingDescription"=>$this->starRatingDescription);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the StarRatings object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"star_ratings\">\n";
		$htmlCode .= '	<div class="star_ratings_starRatingId">'.(($escapeHTML===true) ? htmlspecialchars($this->starRatingId) : $this->starRatingId)."</div>\n";
		$htmlCode .= '	<div class="star_ratings_starRatingCode">'.(($escapeHTML===true) ? htmlspecialchars($this->starRatingCode) : $this->starRatingCode)."</div>\n";
		$htmlCode .= '	<div class="star_ratings_starRatingDescription">'.(($escapeHTML===true) ? htmlspecialchars($this->starRatingDescription) : $this->starRatingDescription)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/


	public static function loadAll(){
		$starRatings = new StarRatings();
		$rows = $starRatings->dao->getData("");
		$starRatingss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new StarRatings();
			$d->init($rows[$index]);
			array_push($starRatingss,$d);
		}
		return $starRatingss;
	}


	/**
	 * Load the StarRatings uniquely by its primary key.
	 * @param starRatingId the primary key
	 * @return StarRatings Instance of {@link StarRatings}
	 */
	public static function loadUnique($starRatingId){
		$starRatings = new StarRatings();
		$rows = $starRatings->dao->getData("`starRatingId`='$starRatingId'");
		$starRatings->init($rows[0]);
		return $starRatings;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("starRatingId"=>$this->starRatingId, "starRatingCode"=>$this->starRatingCode, "starRatingDescription"=>$this->starRatingDescription);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("starRatingId"=>$this->starRatingId, "starRatingCode"=>$this->starRatingCode, "starRatingDescription"=>$this->starRatingDescription);
		$where = "`starRatingId`='$starRatingId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['starRatingId'])){
			$this->starRatingId = $_POST['starRatingId'];
		}
		if (isset($_POST['starRatingCode'])){
			$this->starRatingCode = $_POST['starRatingCode'];
		}
		if (isset($_POST['starRatingDescription'])){
			$this->starRatingDescription = $_POST['starRatingDescription'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['starRatingId'])){
			$this->starRatingId = $_GET['starRatingId'];
		}
		if (isset($_GET['starRatingCode'])){
			$this->starRatingCode = $_GET['starRatingCode'];
		}
		if (isset($_GET['starRatingDescription'])){
			$this->starRatingDescription = $_GET['starRatingDescription'];
		}
	}


	/**
	 * Returns the value from the database field starRatingId.
	 * In the database the field starRatingId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getStarRatingId(){
		return $this->starRatingId;
	}


	/**
	 * Set the value from the database field starRatingId.
	 * In the database the field starRatingId is of type int.
	 * The database field is NOT nullable.
	 * @param starRatingId String with the value for the field to be set
	 */
	public function setStarRatingId($starRatingId){
		$this->starRatingId = $starRatingId;
	}


	/**
	 * Returns the value from the database field starRatingCode.
	 * In the database the field starRatingCode is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getStarRatingCode(){
		return $this->starRatingCode;
	}


	/**
	 * Set the value from the database field starRatingCode.
	 * In the database the field starRatingCode is of type varchar.
	 * The database field is  nullable.
	 * @param starRatingCode String with the value for the field to be set
	 */
	public function setStarRatingCode($starRatingCode){
		if(strlen($starRatingCode) > 10) throw new Exception("starRatingCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($starRatingCode)." characters.");
		$this->starRatingCode = $starRatingCode;
	}


	/**
	 * Returns the value from the database field starRatingDescription.
	 * In the database the field starRatingDescription is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getStarRatingDescription(){
		return $this->starRatingDescription;
	}


	/**
	 * Set the value from the database field starRatingDescription.
	 * In the database the field starRatingDescription is of type varchar.
	 * The database field is  nullable.
	 * @param starRatingDescription String with the value for the field to be set
	 */
	public function setStarRatingDescription($starRatingDescription){
		if(strlen($starRatingDescription) > 45) throw new Exception("starRatingDescription does not allow strings longer than 45 characters. The submitted string contains ".strlen($starRatingDescription)." characters.");
		$this->starRatingDescription = $starRatingDescription;
	}
}
?>